package lec02.am.ex;

import java.util.Arrays;

public class ArraySolver2 {

	private static final int SIZE = 100;
	static long H[];

	static void fill() {
		H = new long[SIZE + 1];
		for (int i = 1; i < H.length; i++) {
			H[i] = h(i);
		}
	}

	public static void solve() {
		fill();
		int a, b, c, d, e, f;
		for (a = 1; a <= SIZE; a++)
			for (b = a; b <= SIZE; b++)
				for (c = b; c <= SIZE; c++)
					for (d = c; d <= SIZE; d++)
						for (e = d; e <= SIZE; e++) {
							int pos = Arrays.binarySearch(H, H[a] + H[b] + H[c]
									+ H[d] + H[e]);
							if (pos >= 0) {
								System.out.println(String.format(
										"%d^5+%d^5+%d^5+%d^5=%d^5", a, b, c, d,
										e, pos));
							}
						}

	}

	private static long h(int a) {
		return 1L * a * a * a * a * a;
	}

}
